.ai-sidebar-wrapper {
  position: fixed; /* 使用fixed而非absolute，确保不影响文档流 */
  width: 33.33%;
  max-width: 500px; /* 防止在大屏幕上过宽 */
  min-width: 300px; /* 确保在小屏幕上依然有足够空间 */
  height: 100%;
  right: 0;
  top: 0;
  overflow: hidden;
  pointer-events: none; /* 默认禁用交互 */
  transform: translateX(100%); /* 默认移出视图 */
  transition: transform 0.3s ease;
  will-change: transform; /* 优化动画性能 */
  z-index: 999; /* 增大z-index确保在所有内容之上 */
  box-shadow: -5px 0 15px rgba(0, 0, 0, 0.2);
  
  &.show {
    transform: translateX(0);
    pointer-events: auto; /* 显示时允许交互 */
  }
}

.ai-sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-width: 0; /* 防止内容溢出 */
  box-sizing: border-box; /* 确保宽度计算包含边框和内边距 */
  background-color: #f8f9fa;
  border-left: 1px solid #e0e0e0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.ai-sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 40px;
  font-weight: bold;
  transition: all 0.3s ease;
  
  &:hover {
    background-color: #e0e0e0;
  }
  
  &:focus {
    outline: none;
  }
}

.ai-sidebar-container {
  height: 100%;
  overflow: hidden;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
}

.ai-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  background-color: #ffffff;
}

.header-buttons {
  display: flex;
  gap: 8px;
}

.title-with-refresh {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-sidebar-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.title-refresh-button {
  background: none;
  border: none;
  color: #0366d6;
  cursor: pointer;
  padding: 3px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  transition: all 0.2s ease;
  
  &:hover {
    background-color: #e6f0fa;
  }
  
  &:active {
    background-color: #c8e1fd;
  }
  
  .refresh-icon {
    display: inline-block;
    font-size: 14px;
    font-weight: bold;
    transform-origin: center;
    transition: transform 0.3s ease;
  }
  
  &:hover .refresh-icon {
    transform: rotate(180deg);
  }
}

.clear-button {
  background: none;
  border: none;
  color: #666;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  
  &:hover {
    background-color: #f0f0f0;
    color: #333;
  }
  
  &:active {
    background-color: #e8e8e8;
  }
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  border-radius: 8px;
  padding: 12px;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.user-message {
  background-color: #e3f2fd;
  align-self: flex-end;
  margin-left: 24px;
}

.assistant-message {
  background-color: #ffffff;
  align-self: flex-start;
  margin-right: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
}

.message-role {
  font-weight: 600;
  color: #555;
}

.message-time {
  color: #888;
}

.message-content {
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  
  /* Markdown样式 */
  h1, h2, h3, h4, h5, h6 {
    margin-top: 16px;
    margin-bottom: 8px;
    font-weight: 600;
    line-height: 1.25;
  }
  
  h1 { font-size: 20px; }
  h2 { font-size: 18px; }
  h3 { font-size: 16px; }
  h4 { font-size: 15px; }
  h5 { font-size: 14px; }
  h6 { font-size: 13px; }
  
  p {
    margin-top: 0;
    margin-bottom: 8px;
  }
  
  a {
    color: #0366d6;
    text-decoration: none;
    &:hover {
      text-decoration: underline;
    }
  }
  
  img {
    max-width: 100%;
    height: auto;
  }
  
  ul, ol {
    padding-left: 20px;
    margin-bottom: 16px;
  }
  
  li {
    margin-bottom: 4px;
  }
  
  blockquote {
    padding: 0 16px;
    margin-left: 0;
    border-left: 4px solid #dfe2e5;
    color: #6c757d;
  }
  
  table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 16px;
    
    th, td {
      padding: 8px 12px;
      border: 1px solid #ddd;
      text-align: left;
    }
    
    th {
      background-color: #f5f5f5;
      font-weight: 600;
    }
    
    tr:nth-child(even) {
      background-color: #f9f9f9;
    }
  }
  
  hr {
    height: 1px;
    background-color: #ddd;
    border: none;
    margin: 16px 0;
  }
}

.message-text {
  margin: 0 0 8px 0;
}

.message-text:last-child {
  margin-bottom: 0;
}

.code-block-wrapper {
  background-color: #f5f5f5;
  border-radius: 4px;
  margin: 8px 0;
  overflow: hidden;
}

.code-block {
  margin: 0;
  padding: 0;
  overflow: auto;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 13px;
  line-height: 1.45;
  background-color: #f5f5f5;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #e8e8e8;
  padding: 6px 12px;
  font-size: 12px;
  color: #555;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

.code-actions {
  display: flex;
  gap: 6px;
}

.copy-button, .apply-button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
}

.copy-button {
  color: #0366d6;
}

.copy-button:hover {
  background-color: #ddd;
}

.apply-button {
  color: #fff;
  background-color: #28a745;
}

.apply-button:hover {
  background-color: #218838;
}

.code-block code {
  display: block;
  padding: 12px;
  overflow-x: auto;
  background-color: transparent;
}

/* 内嵌代码样式 */
:not(pre) > code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  padding: 2px 5px;
  margin: 0 2px;
  border-radius: 3px;
  background-color: #f0f0f0;
  font-size: 85%;
  color: #333;
  border: 1px solid #e1e1e8;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
  text-align: center;
  padding: 0 24px;
}

.empty-state p {
  margin-bottom: 24px;
  font-size: 15px;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestion-chips button {
  background-color: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 13px;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
}

.suggestion-chips button:hover {
  background-color: #f0f0f0;
  border-color: #ccc;
}

.input-container {
  display: flex;
  padding: 12px;
  background-color: #ffffff;
  border-top: 1px solid #e0e0e0;
  gap: 8px;
}

.input-container textarea {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  resize: none;
  max-height: 150px;
  font-family: inherit;
}

.input-container textarea:focus {
  outline: none;
  border-color: #0366d6;
}

.send-button {
  background-color: #0366d6;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.send-button:hover {
  background-color: #0255b3;
}

.send-button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.loading .typing-indicator {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 0;
}

.typing-indicator span {
  height: 8px;
  width: 8px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  animation: typing 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0.7;
  }
}

/* 适配深色模式 */
.dark {
  .ai-sidebar {
    background-color: #1e1e1e;
    border-left: 1px solid #333;
  }
  
  .ai-sidebar-toggle {
    background-color: #333;
    color: #e0e0e0;
    
    &:hover {
      background-color: #444;
    }
  }
  
  .ai-sidebar-header {
    background-color: #252525;
    border-bottom: 1px solid #333;
  }
  
  .ai-sidebar-header h3 {
    color: #e0e0e0;
  }
  
  .clear-button {
    color: #aaa;
  }
  
  .clear-button:hover {
    background-color: #333;
    color: #fff;
  }
  
  .user-message {
    background-color: #0d47a1;
    color: #fff;
  }
  
  .assistant-message {
    background-color: #252525;
    color: #e0e0e0;
  }
  
  .message-role {
    color: #ccc;
  }
  
  .message-time {
    color: #888;
  }
  
  .code-block {
    background-color: #2d2d2d;
  }
  
  .code-header {
    background-color: #333;
    color: #ccc;
  }
  
  .copy-button {
    color: #58a6ff;
  }
  
  .copy-button:hover {
    background-color: #444;
  }
  
  .empty-state {
    color: #aaa;
  }
  
  .suggestion-chips button {
    background-color: #252525;
    border-color: #444;
    color: #e0e0e0;
  }
  
  .suggestion-chips button:hover {
    background-color: #333;
    border-color: #555;
  }
  
  .input-container {
    background-color: #252525;
    border-top: 1px solid #333;
  }
  
  .input-container textarea {
    background-color: #1e1e1e;
    border-color: #444;
    color: #e0e0e0;
  }
  
  .input-container textarea:focus {
    border-color: #58a6ff;
  }
  
  .send-button {
    background-color: #0366d6;
  }
  
  .send-button:hover {
    background-color: #0255b3;
  }
  
  .send-button:disabled {
    background-color: #444;
  }
}